//
//  MZNavigationVC.m
//  minzu
//
//  Created by mac1 on 2025/7/3.
//

#import "MZNavigationVC.h"

@interface MZNavigationVC ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>

@end

@implementation MZNavigationVC


- (void)viewDidLoad {
    [super viewDidLoad];
    // 1.设置导航条的背景颜色
    // 修改导航条上左边右边以及返回按钮文字颜色,不包括中间的标题文字颜色
    //    self.navigationBar.tintColor
        
    // 清空导航条自带的背景图片
    [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    // 清空导航条上自带的阴影"一定要注意不要传nil应该传一个空image"
    self.navigationBar.shadowImage = [UIImage new];
    // 以上两句一起使用才能把导航条自带的阴影线取消掉
    
    // 设置导航条及状态栏的背景色
//    self.navigationBar.barTintColor = navigationBGColor;
    self.navigationBar.barTintColor = [UIColor whiteColor];

    // 关闭导航条的透明效果
    self.navigationBar.translucent = NO;
    
    // 2.更改导航条标题的文字颜色
    self.navigationBar.titleTextAttributes = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:18], NSForegroundColorAttributeName : [UIColor blackColor]};
    
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = self;
        self.delegate = self;
    }
    
    UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
    [appearance configureWithOpaqueBackground];
    // 改变导航栏的颜色
    appearance.backgroundColor = [UIColor whiteColor];
    // 改变导航栏的标题颜色
    appearance.titleTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],
                                             NSForegroundColorAttributeName:[UIColor blackColor]};
    //导航栏包含状态栏 阴影线颜色背景色设置
    appearance.shadowColor =[UIColor whiteColor];
    // 静止样式
    self.navigationBar.standardAppearance = appearance;
    // 滚动样式
    self.navigationBar.scrollEdgeAppearance = self.navigationBar.standardAppearance;
      
}
// 状态栏样式设置
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

// 全体改导航条代码和push取消底部tabbar
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count != 0) {
        
        viewController.hidesBottomBarWhenPushed = YES;
        viewController.tabBarController.tabBar.hidden = YES;
        
        UIView *butV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 40)];
        UIImageView *imV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 20, 20)];
        imV.image = [UIImage imageNamed:@"backBtn"];
        [butV addSubview:imV];
        UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        leftButton.frame = CGRectMake(0, 0, 50, 40);
        [butV addSubview:leftButton];
        [leftButton addTarget:self action:@selector(LeftClick) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:butV];
        
    } else {
        viewController.hidesBottomBarWhenPushed = NO;
        viewController.tabBarController.tabBar.hidden = NO;
    }
    [super pushViewController:viewController animated:animated];
}

- (void)LeftClick {
    [self popViewControllerAnimated:YES];
}

@end
